import pandas as pd
def main():
    data = pd.read_excel('/Users/meichaoyang/Downloads/house_price.xlsx')
    data = data[['日期', '总价（万）']]

    data['日期'] = pd.to_datetime(data['日期'], format="%Y年%m月%d日", errors='coerce')
    data = data[data['日期'] < '2024-02-01']

    data['总价（万）'] = data['总价（万）'].astype(str)
    data['总价（万）'] = data['总价（万）'].str.replace('万', '')

    data['总价（万）'] = pd.to_numeric(data['总价（万）'], errors='coerce')
    data = data.dropna()

    print(data.to_json(force_ascii=False, orient='records'))

def main1():
    data = pd.read_excel('test.xlsx')
    data = data[['日期', '总价（万）']]

    data['总价（万）'] = data['总价（万）'].astype(str)
    data['总价（万）'] = data['总价（万）'].str.replace('万', '')

    data['总价（万）'] = pd.to_numeric(data['总价（万）'], errors='coerce')
    data = data.dropna()

    print(data.to_json(force_ascii=False, orient='records'))

def main2():
    ### example2：饼状图数据处理示例
    data = data[['面积（平米）']]
    data['面积（平米）'] = pd.to_numeric(data['面积（平米）'], errors='coerce')
    bins = list(range(0, int(data['面积（平米）'].max()) + 20, 20))
    data['面积分段'] = pd.cut(data['面积（平米）'], bins)
    area_distribution = data.groupby('面积分段').size().reset_index()
    area_distribution.columns = ['面积分段', '数量']
    area_distribution = area_distribution[area_distribution['数量'] > 0]
    area_distribution['面积分段'] = area_distribution['面积分段'].astype(str)
    result_df = area_distribution[['面积分段', '数量']]
    result = result_df.to_json(force_ascii=False, orient='records')
    print(result)

def main3():
    ### example3：柱状图的数据处理示例
    import pandas as pd
    data = pd.read_excel('/Users/mingcui/Programs/xyz/test-ppt/test_excel/test.xlsx')
    data = data[['朝向']]
    orientation_distribution = data['朝向'].value_counts().reset_index()
    orientation_distribution.columns = ['朝向', '数量']
    result = orientation_distribution.to_json(force_ascii=False, orient='records')
    print(result)

def main4():
    data = pd.read_excel('/Users/meichaoyang/Downloads/test.xlsx')
    data = data[['日期', '总价（万）']]

    data['总价（万）'] = data['总价（万）'].astype(str)
    data['总价（万）'] = data['总价（万）'].str.replace('万', '')

    data['总价（万）'] = pd.to_numeric(data['总价（万）'], errors='coerce')
    data = data.dropna()

    print(data.to_json(force_ascii=False, orient='records'))

def main5():
    data = pd.read_excel('/Users/meichaoyang/Downloads/test.xlsx')
    data = data[['面积（平米）']]
    data['面积（平米）'] = pd.to_numeric(data['面积（平米）'], errors='coerce')
    bins = list(range(0, int(data['面积（平米）'].max()) + 20, 20))
    data['面积分段'] = pd.cut(data['面积（平米）'], bins)
    area_distribution = data.groupby('面积分段').size().reset_index()
    area_distribution.columns = ['面积分段', '数量']
    area_distribution = area_distribution[area_distribution['数量'] > 0]
    area_distribution['面积分段'] = area_distribution['面积分段'].astype(str)
    result_df = area_distribution[['面积分段', '数量']]
    result = result_df.to_json(force_ascii=False, orient='records')
    print(result)

def main6():
    data = pd.read_excel('/Users/meichaoyang/Downloads/test.xlsx')
    data = data[['朝向']]
    orientation_distribution = data['朝向'].value_counts().reset_index()
    orientation_distribution.columns = ['朝向', '数量']
    result = orientation_distribution.to_json(force_ascii=False, orient='records')
    print(result)

# main()
# main4()
# main5()
main6()
